{% load full_mock_url %}

<!DOCTYPE html 
    PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
    
    <head>
        <title>htmock: {{ resource.label }}</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="stylesheet" href="{{ MEDIA_URL }}styles.css" type="text/css">
    </head>
    
    <body>
        <h1><a href="{% url inspect-index %}">htmock</a>: {{ resource.label }}</h1>
        <p><a href="{% full_mock_url resource request %}">{% full_mock_url resource request %}</a></p>
        <p>Created: {{ resource.created_on|date:"Y-m-d H:i" }}</p>
        <p>Alive until: {{ resource.alive_until|date:"Y-m-d H:i" }}</p>
        <p>Hit count: {{ resource.requests.count }}</p>
        
        <form action="{% url inspect-resource resource.label %}" method="post">
            <div>
                <input type="hidden" name="X-HTTP-Method-Override" value="DELETE">
                <input type="submit" value="Delete">
            </div>
        </form>
        
        {% if resource.requests.count > 0 %}
            <h2>Requests for this resource</h2>
            {% for request in resource.requests.all %}
            
                <h3>{{ request.method }} on {{ request.received_on|date:"Y-m-d H:i" }}</h3>
                
                {% if request.remote_addr %}
                    <p>From {{ request.remote_addr }}</p>
                {% endif %}
                
                {% with request.headers as headers %}
                    <table>
                        <caption>Request headers</caption>
                        <tbody>
                            {% for field_name, field_value in headers.items %}
                                <tr>
                                    <td>{{ field_name }}</td>
                                    <td>{{ field_value }}</td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                {% endwith %}
                
                {% with request.get_params as get %}
                    {% if get|length > 0 %}
                        <table>
                            <caption>Query string parameters</caption>
                            <tbody>
                                {% for name, value in get.items %}
                                    <tr>
                                        <td>{{ name }}</td>
                                        <td>{{ value }}</td>
                                    </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    {% endif %}
                {% endwith %}
                
                {% if request.query_string|length > 0 %}
                    <p>Raw query string:</p>
                    <pre>{{ request.query_string }}</pre>
                {% endif %}
                
                {% with request.post_params as post %}
                    {% if post|length > 0 %}
                        <table>
                            <caption>URL-encoded parameters in request body</caption>
                            <tbody>
                                {% for name, value in post.items %}
                                    <tr>
                                        <td>{{ name }}</td>
                                        <td>{{ value }}</td>
                                    </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    {% endif %}
                {% endwith %}
                
                {% if request.data|length > 0 %}
                    <p>Raw request body:</p>
                    <pre>{{ request.data }}</pre>
                {% endif %}
            
            {% endfor %}
        {% endif %}
    </body>
    
</html>
